function [scheduledTargets, scheduledPriorities, status] = SCP_InsertInterval(scheduledTargets, scheduledPriorities, relations, target_id, priority)
%SCP_InsertInterval Summary of this function goes here
%   Detailed explanation goes here

status = 1;

if length(scheduledTargets) < 1
  scheduledTargets = target_id;
  scheduledPriorities = priority;
  return;
end

added = 0;
for k = 1:length(scheduledTargets)
  relation = IA_Relation_Intersect(IA_Relation_Greater(), relations(k));
  if IA_Relation_Is_Null(relation)
    scheduledTargets = [scheduledTargets(1:k-1) target_id scheduledTargets(k:length(scheduledTargets))];
    scheduledPriorities = [scheduledPriorities(1:k-1) priority scheduledPriorities(k:length(scheduledPriorities))];
    added = 1;
    break;
  end
end

if ~added
  scheduledTargets = [scheduledTargets target_id];
  scheduledPriorities = [scheduledPriorities priority];
end

end % function